package com.rednote.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rednote.entity.UserViewHistory;
import com.rednote.service.UserViewHistoryService;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;

/**
 * 用户浏览记录表(UserViewHistory)控制层
 *
 * @author yao suxuan
 * @since 2025-05-24 18:10:29
 */
@RestController
@RequestMapping("/userViewHistory")
public class UserViewHistoryController {
    @Resource
    private UserViewHistoryService userViewHistoryService;

    /**
     * 分页查询
     *
     * @param page 页码
     * @param size 每页大小
     * @return 查询结果
     */
    @GetMapping
    public Page<UserViewHistory> list(@RequestParam(defaultValue = "1") Integer page, 
                                        @RequestParam(defaultValue = "10") Integer size) {
        return userViewHistoryService.page(new Page<>(page, size));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public UserViewHistory getById(@PathVariable Long id) {
        return userViewHistoryService.getById(id);
    }
    
    /**
     * 新增数据
     *
     * @param userViewHistory 实体对象
     * @return 新增结果
     */
    @PostMapping
    public boolean save(@RequestBody UserViewHistory userViewHistory) {
        return userViewHistoryService.save(userViewHistory);
    }

    /**
     * 修改数据
     *
     * @param userViewHistory 实体对象
     * @return 修改结果
     */
    @PutMapping
    public boolean update(@RequestBody UserViewHistory userViewHistory) {
        return userViewHistoryService.updateById(userViewHistory);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除结果
     */
    @DeleteMapping("{id}")
    public boolean deleteById(@PathVariable Long id) {
        return userViewHistoryService.removeById(id);
    }
}
